import React, { Component } from 'react'

class Parent extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataFromChild: null
        }
    }
    tsxn = (dataFromChild) => {
        console.log('data from child', dataFromChild)
        this.setState({
            dataFromChild: dataFromChild
        })
    }
    render() {
        return (
            <div>
                <p>{ this.state.dataFromChild }</p>
                <Child name='lingwei' onParentToChild={this.tsxn} />
            </div>
        )
    }
}

class Child extends Component {
    constructor(props) {
        super(props)
        this.state = {
            childName: 'zeng'
        }
    }
    render() {
        let name = this.props.name
        return (
            <div>
                <p>{ name } { this.state.childName }</p>
            </div>
        )
    }
}

export default Parent
